package com.yizhubao.app.utils.net;


import com.yizhubao.app.base.BaseResultBean;

import h.framework.pacy.utils.LogUtil;
import h.framework.pacy.utils.PreferencesUtil;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * @author PACY
 * 创建时间 19/1/10 16:30.
 * 邮箱 pengwwe457621023@qq.com
 * 类描述 统一处理请求结果
 */
public abstract class BaseObserver<T> implements Observer<BaseResultBean<T>> {
    @Override
    public void onSubscribe(Disposable d) {

    }

    @Override
    public void onComplete() {

    }

    public void onLogin(){

    }

    @Override
    public void onError(Throwable e) {
        onError("请求失败,请重试");
        LogUtil.e("请求失败==="+e.toString());
    }

    @Override
    public void onNext(BaseResultBean<T> t) {
        if(t.getCode()==99999){
//            PreferencesUtil.clearValues();
            onLogin();
        }else{
            if(t.isSuccess()){
                onSuccess(t);
            }else{
                onError(t.getMsg());

            }
        }

    }

    //具体实现下面两个方法，便可从中得到更直接详细的信息
    public abstract void onSuccess( BaseResultBean<T> t);
    public abstract void onError(String errMessage);
}
